home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: DelDupes.br 1.3 (18.10.96)
- ** by Eirik Nicolai Synnes
- **
- ** This script will delete duplicate entries in the file database. The first
- ** occurence of each filename will be kept, subsequent occurences IN ANY FILE
- ** AREA will be deleted. (currently, I'll do something about this later)
- **
- **
- ** Usage: DelDupes.br SYSTEM/M,ALL/S,PURGE/S,QUIET/S
- **
- ** Args: SYSTEM The name of the system you want to check. Multiple
- ** systems can be specified
- ** ALL Check dupes on all systems
- ** PURGE Perform file database maintainance afterwards
- ** QUIET Don't display any progress information
- **
- ** Example: DelDupes.br "Ygdrasil" "Ultima Thule" PURGE
- **
- **
- ** Ideas: GUI interface if run from Thor
- ** Support SortMail's exclude file
- ** Allow identical filenames across file areas
- **
- */
-
- options results
-
- signal on break_c
- signal on halt
-
- trace off
-
- parse arg arguments
-
- /* Find BBSREAD ARexx ports' */
-
- if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
-
- /* Parse command line arguments */
-
- template = 'SYSTEM/M,PURGE/S,QUIET/S,ALL/S'
- args.ALL = 0; args.PURGE = 0; args.QUIET = 0
-
- if arguments = '' then do
- say 'Template: 'template
- exit(0)
- end
-
- address(bbsread)
- 'READARGS 'template' 'args' CMDLINE 'arguments
- if rc ~= 0 then do
- say BBSREAD.LASTERROR
- say 'Template: 'template
- exit(0)
- end
-
- if (symbol('args.SYSTEM.COUNT') = 'VAR') & (args.ALL) then do
- say 'You must specify either one or more system names or ALL.'
- say 'Template: 'template
- exit(0)
- end
-
- if args.ALL then GETBBSLIST args.SYSTEM
-
- FDF_DELETED = '00000001'x
-
- totchecked = 0; dupes = 0;
-
- do h = 1 to args.SYSTEM.COUNT
-
- /* Initialize variables */
-
- checked = 0; dupeshere = 0
-
- /* Start the work... */
-
- 'GETFAREALIST BBSNAME "'args.SYSTEM.h'" STEM 'fareas
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
-
- if fareas.COUNT = 0 then do
- say 'No file areas on this system.'
- exit(0)
- end
-
- if ~args.QUIET then say '1B'x'[4mChecking for dupes on "'args.SYSTEM.h'" - 'fareas.COUNT' file areas.' || '1B'x'[0m' || '1B'x'[1B'
-
- do i = 1 to fareas.COUNT
- drop fadata.
- 'GETFAREADATA BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" STEM 'fadata
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
-
- if ~args.QUIET then do
- say '1B'x'[1A' || '1B'x'[K' || '1B'x'[1m'fareas.i || '1B'x'[0m'
- say '1B'x'[1A' || '1B'x'[20Ccontains 'fadata.NUMFILES' files.'
- say '1B'x'[1A' || '1B'x'[42C' || '1B'x'[3mProcessing...' || '1B'x'[0m' || '1B'x'[1B'
- end
-
- thisfile = fadata.FIRSTFILE
-
- if fadata.NUMFILES > 0 then do until checked = fadata.NUMFILES
- drop filetags. filedata. found.
- 'READBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" FILENR 'thisfile' TAGSSTEM 'filetags' DATASTEM 'filedata
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
- nextfile = result
-
- if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then do
- 'SEARCHBRFILE BBSNAME "'args.SYSTEM.h'" STEM 'found' SEARCH "'filetags.NAME'" NAME'
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
-
- do j = 1 to found.FILEAREA.COUNT
- do k = 1 to found.FILE.j.COUNT
- if found.FILE.j.k ~= thisfile then do
- if ~args.QUIET then say '1B'x'[1A' || '1B'x'[KDupe: 'found.FILEAREA.j'/'filetags.NAME
- 'WRITEBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'found.FILEAREA.j'" UPDATEFILENR 'found.FILE.j.k' DELETEFILE'
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
-
- if ~args.QUIET then say '1B'x'[1A' || '1B'x'[42CDELETED'
- dupes = dupes + 1; dupeshere = dupeshere + 1
- end
- end
- end
-
- checked = checked + 1; totchecked = totchecked + 1
- thisfile = nextfile
- end
- end
-
- if ~args.QUIET then say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[K'dupeshere' dupes found.' || '1B'x'[1B'
- checked = 0; dupeshere = 0
- end
-
- if args.PURGE & ~args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA SHOWPROGRESS'
- if args.PURGE & args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA'
- if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
- end
-
- break_c:
- halt:
- if ~args.QUIET then say 'Checked 'totchecked' files and found 'dupes' duplicates.'
-